const cors = require('cors');

// 白名单允许跨域的源
const whiteList = [
    "null",
    "http://localhost:8080",
    "http://localhost:8000",
    "http://192.168.1.106:8001"
];

module.exports = cors({
    origin(origin, callback) {
        if (!origin) {
            callback(null, "*");
            return;
        }
        if (whiteList.includes(origin)) {
            callback(null, origin);
        } else {
            callback(new Error("not allowed"));
        }
    },
    credentials: true, //表示允许附带cookie
});